import java.util.*;
import java.io.*;
import javax.swing.*;

public class ReadFileUsingFileChooser {
    public static void main(String[] args) throws Exception {
        JFileChooser fileChooser = new JFileChooser();
        if (fileChooser.showOpenDialog(null)
                == JFileChooser.APPROVE_OPTION) {
            File file = fileChooser.getSelectedFile();
            Scanner scan = new Scanner(file);
            
            while(scan.hasNext()) {
                System.out.println(scan.nextLine());
            }
            
            scan.close();
        }
        else {
            System.out.println("No file selected...");
        }
    }
}